package org.usmile.algorithms.huawei.acm;

import java.util.HashMap;
import java.util.Scanner;

// https://blog.csdn.net/qfc_128220/article/details/128561896
public class _识图谱新词挖掘 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String content = sc.next();
        String word = sc.next();

        System.out.println(getResult(content, word));
    }

    public static int getResult(String content, String word) {
        if (content.length() < word.length()) {
            return 0;
        }

        int total = 0;
        int needMatch = word.length();
        HashMap<Character, Integer> count = new HashMap<>();
        for (int i = 0; i < word.length(); i++) {
            Character c = word.charAt(i);
            count.put(c, count.getOrDefault(c, 0) + 1);
        }

        for (int i = 0; i < word.length(); i++) {
            Character c = content.charAt(i);
            if (count.containsKey(c)) {
                if (count.get(c) > 0) {
                    needMatch--;
                }
                count.put(c, count.get(c) - 1);
            }
        }

        if (needMatch == 0) {
            total++;
        }
        for (int i = 1; i <= content.length() - word.length(); i++) {
            Character leftChar = content.charAt(i - 1);
            Character rightChar = content.charAt(i + word.length() - 1);
            if (count.containsKey(leftChar)) {
                if (count.get(leftChar) >= 0) {
                    needMatch++;
                }
                count.put(leftChar, count.get(leftChar) + 1);
            }
            if (count.containsKey(rightChar)) {
                if (count.get(rightChar) > 0) {
                    needMatch--;
                }
                count.put(rightChar, count.get(rightChar) - 1);
            }
            if (needMatch == 0) {
                total++;
            }
        }

        return total;
    }
}
